package com.hhf.rpa.ScreenRecorderTest;

import java.awt.*;
import java.awt.event.AWTEventListener;
import java.awt.event.MouseEvent;

/**
 * 监听AWT窗口的鼠标事件
 */
public class AWTExample {
    public static void main(String[] args) {
        // 创建一个新的Frame
        Frame frame = new Frame("AWT Event Listener Example");
        frame.setSize(300, 200);
        frame.setLayout(new FlowLayout());

        // 添加几个按钮到Frame
        Button button1 = new Button("Button 1");
        Button button2 = new Button("Button 2");
        frame.add(button1);
        frame.add(button2);

        // 设置全局AWT事件监听器
        Toolkit.getDefaultToolkit().addAWTEventListener(new AWTEventListener() {
            @Override
            public void eventDispatched(AWTEvent event) {
                if (event instanceof MouseEvent) {
                    System.out.println("Mouse event detected: " + event);
                }
            }
        }, AWTEvent.MOUSE_EVENT_MASK);

        // 显示Frame
        frame.setVisible(true);
    }
}
